
#include "main.h"
#include "key.h"
#include "Common.h" 
extern u8  Fcn;
u8  Sk_Mode_Table[10]={3,4,5,6,7,8,9,12,12,14};
void  key_managent(void)
{
  // KEY();
   if(key)
  {
   	switch(key)
   {
      case  K1:  
	  			
				if(Mode==0)
				{
					Mode=Mode_buff;
					ct = 0;
				}
				else //if(Mode<26)
				{
					if(music)
					{
						Mode=Mode_buff;
					}
					else
					{
						Mode++;
						if(Mode==25)
						{
							Mode=3;
						}
					}
					if(ct>0)
					{
						ct=0;
					}
					else
					{
						ct=1;
					}
					if(Mode>9)
					 sp1=500;
				}
         break;
     case  K2:     
			if(Mode==0)
			{
				Mode=Mode_buff;
				ct = 0;
			}
			else //if(Mode>3)
			{
				if(music)
				{
					Mode=Mode_buff;
				}
				else
				{
					Mode--;
					if(Mode==2)
					{
						Mode=24;
					}
			  }
				if(ct>0)
				{
					ct=0;
				}
				else
				{
					ct=1;
				}
				if(Mode>9)
				sp1=500;
			}
			break;
////////////////////////////////////////////////////////			  
	case  K3:                             //??+
	          if(Mode>7) //&&(On_off)
						{
	               if(Speed_class<9)
									Speed_class++;
								 else
									Speed_class=9;
						}
						break;
    case  K4:                           //??-
						if(Mode>7)// &&(On_off)
						{
								if(Speed_class>0)
								   Speed_class--;
							  else
								   Speed_class=0;
					  }
						break;
      case  K5:                       //??+
					if(dim<9)
			   	  dim++;
			    else
			      dim=9;		
			    break;    
      case  K6:                       //??-
	  	    if(dim>0)
				  {
						dim--;
						if((Mode==11)||(Mode==13)||(Mode==14)||(Mode==15))
						{
							// Out.R=Out.R>>
						  //  sp1=0;
						  // dim_val=dim_table[dim];
							ii=dim_table[dim]-5;
						}
							//ii=0; 
			    }
				  else
				   dim=0;
              break;
///////////////////////////////////////////////////////  
      case  K7:                     //k_music+  
			    if((Mode>2)&&!music)
					{
					  Mode_buff=Mode;
				  }
					if(music)
					{
						Sk_Mode++;
						if(Sk_Mode>9)
						{
							Sk_Mode = 0;
						}
						/*if((Sk_Mode<3)||(Sk_Mode>24))
						{
							Sk_Mode = 3;
						}*/
				  }
					if(ct>0)
					{
						ct=0;
					}
					else
					{
						ct=1;
					}
					//if(Sk_Mode>9)
				     //sp1=100;
          //Mode_buff=Mode;      
					//Mode =1 ;
          break; 
      case  K8:                     //k_music-
			    if((Mode>2)&&!music)     //?????(????????,???????)????????
					{
					  Mode_buff=Mode;
				  }
					if(music)
					{
						if(Sk_Mode>0)
						{
							Sk_Mode--;
						}
						else
						{
							Sk_Mode=9;
						}
						/*if(Sk_Mode>3)
						{
							Sk_Mode--;
						}
						else if(Sk_Mode<=3)
						{
							Sk_Mode=24;
						}*/
				  }
					if(ct>0)
					{
						ct=0;
					}
					else
					{
						ct=1;
					}
					//if(Sk_Mode>9)
				     //sp1=100;
        //Mode_buff=Mode;      
				//Mode =2;
          break; 
///////////////////////////////////////////////////////  
      case  K9:                     //?
					On_off=SET;
			 //  if(Storage==RESET)
				//Read_eerom();
			   if(Mode==0)
				 {
			   		hualun(Yh_val);
				 }
			   else if(Mode>7)
				 {
			   	  sp1=100;
				 }
				 break;
      case  K10:                    //?
				On_off=RESET;
				Out.R=0;
				Out.G=0;
				Out.B=0;
				buff.R=0;
				buff.G=0;
				buff.B=0;
				temp.R=0;
				temp.G=0;
				temp.B=0;
        break; 
/////////////////////////////////////////////////			  
        default:    
         break;  
     }
		 Storage=SET;
		 Storage_time=0;
		 //ct=0;
		 if((key==K7)||(key==K8))
		 {
			 /*if(Mode==0)
			 {
			   Mode=Mode_buff;
			 }
			 else*/
			 {
				 Mode=Sk_Mode_Table[Sk_Mode];   //??????
			 }
			 music=1;
		 }
		 else if((key==K1)||(key==K2))
		 {
			 if(music)   //???????  ????
			 {
				 Mode=Mode_buff;
			 }
			 music=0;
			 music_ok=0;
		 }
		 Fcn=0;
   	}
 }
